package com.authine.cloudpivot.web.api.quartz.task;

import com.alibaba.dubbo.config.annotation.Reference;
import com.authine.cloudpivot.engine.api.facade.TaskReportFacade;
import com.authine.cloudpivot.web.api.dao.UserMapper;
import com.authine.cloudpivot.web.api.service.impl.FescoadQueryServiceImpl;
import com.authine.cloudpivot.web.api.vo.User;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
public class RemindUnReviewedReportJob implements Job {
    @Reference(version = "1.00")
    private TaskReportFacade taskReportFacade;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private FescoadQueryServiceImpl fescoadQueryService;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        log.info("周报未复核提醒开始------------------------------------");
        JobDataMap jobDataMap = context.getMergedJobDataMap();
        String type =  jobDataMap.get("data1").toString();
        Map<String, String> map  =  taskReportFacade.getUnReviewedReportTips(type);
        for(String key : map.keySet()){
            log.info(userMapper.getUserId(key).getName()+map.get(key)+"周报还未复核，请尽快复核!");
            fescoadQueryService.sendTextMessage(key,"",map.get(key)+"周报还未复核，请尽快复核!","周报复核提醒");
        }
        log.info("周报未复核提醒结束------------------------------------");
    }
}
